FUN The most popular computer language is BASIC, which I explained earlier. Now you'll learn a different computer language, called FORTRAN. Most maxicomputers and minicomputers understand both BASIC and FORTRAN. Some ideas are easier to express in BASIC; others are easier in FORTRAN. Most scientists and engineers on large computers use FORTRAN, not BASIC. IBM invented the first version of FORTRAN in 1957. Then came improvements, called FORTRAN II, FORTRAN III, and FORTRAN IV. The next version was called FORTRAN 77 because it was invented in 1977. The newest version is called FORTRAN 90 because it was invented in 1990. Some computers use FORTRAN 77 or FORTRAN 90. Others still use FORTRAN IV or a slightly souped-up version of it (called FORTRAN IV-EXTENDED or FORTRAN V or WATFOR or WATFIV or FORTRAN 10). This chapter explains the popular FORTRAN features that work on practically all computers. Simple programs Here's a FORTRAN program: PRINT 10 10 FORMAT (1X,'CHIPMUNKS ARE CHUBBY') PRINT 20 20 FORMAT (1X,'GOLDFISH GIGGLE') PRINT 10 END The top line says to print what's in line 10, so the computer will print CHIPMUNKS ARE CHUBBY. The next line says to print what's in line 20, so the computer will print GOLDFISH GIGGLE. The next line says to print what's in line 10, so the computer will print CHIPMUNKS ARE CHUBBY again.Altogether, the program makes the computer print: CHIPMUNKS ARE CHUBBY GOLDFISH GIGGLE CHIPMUNKS ARE CHUBBY Notice: Each program line is indented 6 spaces, so it begins in the 7th position. Each FORMAT begins with 1X. Each string is enclosed in apostrophes. You must number every line that's referred to. For example, you must number the FORMAT lines, since the PRINT lines refer to them. You don't have to number the PRINT lines. The bottom line of every FORTRAN program must be END. Different versions On PDP computers, say TYPE instead of PRINT. On CDC computers using TS FORTRAN, replace each apostrophe by an asterisk. On IBM computers, put STOP above END, so the bottom two lines of your program are: STOP END How to type the program Ask the people in your computer center how to feed a FORTRAN program into the computer. On some computers, you must put an edit number in front of each line: 00100 PRINT 10 00110 10 FORMAT (1X,'CHIPMUNKS ARE CHUBBY') 00120 PRINT 20 00130 20 FORMAT (1X,'GOLDFISH GIGGLE') 00140 PRINT 10 00150 END Some computers don't require you to indent each line. To indent quickly on PDP computers, hold down the CONTROL key, while you type the letter I. Be brief Each line of your program must be brief: no more than 72 characters, including the spaces at the beginning of the line. Carriage controls The 1X at the beginning of each FORMAT is called the carriage control. It means: print the format normally. For weirder printing, replace the 1X by '0' or '1' or '+': PRINT 10 10 FORMAT (1X,'NIFTY') PRINT 20 20 FORMAT ('0','SAL') END In line 10, the 1X makes the computer print NIFTY normally. In line 20, the zero-in-apostrophes make the computer leave a blank line, then print SAL. The computer will print: NIFTY SAL Suppose you change the carriage control to '1': PRINT 10 10 FORMAT (1X,'NIFTY') PRINT 20 20 FORMAT ('1','SAL') END If your terminal uses paper, the '1' makes the computer print SAL on a new page. If your terminal uses a screen instead of paper, the '1' makes the computer erase the screen before printing SAL. Suppose you change the carriage control to '+': PRINT 10 10 FORMAT (1X,'NIFTY') PRINT 20 20 FORMAT ('+','SAL') END If your terminal uses paper, the '+' makes the computer print SAL in the same place as NIFTY, like this: NIFTYSAL If your terminal uses a screen instead, the computer will print NIFTY, but then the NIF will suddenly disappear, and you'll see SALTY. To print the symbol 0-, print 0 in the same place as -. To print the symbol =/, print = in the same place as /. To print 0=-/A, print 0=A in the same place as -/. If your terminal uses paper, the program prints 0=-/A: PRINT 10 10 FORMAT (1X,'0=A') PRINT 20 20 FORMAT ('+','-/') END Different versions If you're using a Hazeltine terminal or CDC TS FORTRAN, the carriage controls won't work. Fancy formats In the format line, you can play fancy tricks. Multiple fields Examine this program: PRINT 10 10 FORMAT (1X,'JOHN','NY') END The FORMAT consists of three fields: the first is the carriage control 1X, the second is `JOHN', and the third is `NY'. The computer will print JOHN and NY on the same line: JOHNNY Another example: PRINT 10 FORMAT (1X,'EAT A',8X,'MEATBALL') END The computer will print EAT A, then 8 blank spaces, then MEATBALL: EAT A MEATBALL This program does the same thing: PRINT 10 10 FORMAT (1X,'EAT A',T15,'MEATBALL') END It makes the computer print EAT A, then Tab over to the 15th position on the line, and print MEATBALL. When the computer tabs to the 15th position, it considers the carriage control to be the first ``position''; the E in EAT is the first character the computer will print, and the computer considers it to be the second ``position''; the A in EAT is the second character the computer will print, and the computer considers it to be the third ``position''; the M in MEATBALL is the 14th character the computer will print, since the T15 says it is the 15th ``position''. Here's another program for meatball lovers: PRINT 10 10 FORMAT (1X,'EAT A',1X,'MEATBALL') The computer will print EAT A, then 1 blank space, then MEATBALL: EAT A MEATBALL If you say X instead of 1X, the computer will gripe. Multiple records This program quotes Julius Caesar: PRINT 10 10 FORMAT (1X,'I CAME') PRINT 20 20 FORMAT (1X,'I SAW') PRINT 30 30 FORMAT (1X,'I CONQUERED') END The computer will print: I CAME I SAW I CONQUERED This program does the same thing: PRINT 10 10 FORMAT (1X,'I CAME'/1X,'I SAW'/1X,'I CONQUERED') END Line 10 consists of 3 records: the first is 1X,`I CAME'; the second is 1X,`I SAW'; the third is 1X,`I CONQUERED'. Each record begins with a carriage control; the records are separated by slashes. The computer will print each record on a separate line. Example: PRINT 10 10 FORMAT (1X,'PLEASE'/1X,'NIBBLE'//1X,'MY'/////1X,'CHEESE') END Line 10 makes the computer print several lines. The first line will say PLEASE. The next line will say NIBBLE. The next line will be blank. The next line will say MY. The next 4 lines will be blank. The last line will say CHEESE. So altogether, the computer will print: PLEASE NIBBLE MY CHEESE Repeated formats The computer can feel very depressed: PRINT 10 10 FORMAT (1X,'I FEEL ',3('DOWN')) END Line 10 is an abbreviation for this format: 1X,'I FEEL ','DOWN','DOWN','DOWN' The computer will print: I FEEL DOWNDOWNDOWN Let's burp and pray: PRINT 10 10 FORMAT (1X,'JACK ',2('BURPS'/1X,'MARY '),'ALSO PRAYS') END Line 10 is an abbreviation for this format: 1X,'JACK ','BURPS'/1X,'MARY ','BURPS'/1X,'MARY ','ALSO PRAYS' The computer will print: JACK BURPS MARY BURPS MARY ALSO PRAYS Double apostrophe To make the computer print an apostrophe, use two apostrophes next to each other. PRINT 10 10 FORMAT (1X,'MOMMY ISN''T HERE') END The computer will print: MOMMY ISN'T HERE Continuation Some computers look at only the first 72 characters of each line of your program: if your line contains more than 72 characters, it won't work. If you want to type a long statement, type just the first 72 characters. On the line below, type the remaining characters, beginning in the 7th print position; and in the 6th print position type a 6: PRINT 10 10 FORMAT (1X,'I LIKE ROSES IN MY TEA.'/1X,'THEY MAKE IT GLOW RED, LI 6KE HOT BLOOD.') END The computer will print: I LIKE ROSES IN MY TEA. THEY MAKE IT GLOW RED, LIKE HOT BLOOD. A line that has a 6 in column 6 is called a continuation line, because it's a continuation of the line above it. (I suggest you put a 6 in column 6, or a * in column 6, or a $ in column 6. In fact, you can put any character in column 6, except a zero. Choose your favorite character; the computer doesn't care.) Different versions On PDP computers, put the 6 immediately after a controlled I, instead of in column 6: 10 FORMAT (1X,'I LIKE ROSES IN MY TEA.'/1X,'THEY MAKE IT GLOW RED, LI 6KE HOT BLOOD.') (I suggest you put a 6 after the controlled I. But you can put in any non-zero digit, instead of a 6.) On CDC computers using TS FORTRAN, type a + instead of a 6, and put it immediately after the edit number, with no intervening spaces: 00120 10 FORMAT (1X,'I LIKE ROSES IN MY TEA.'/1X,'THEY MAKE IT GLOW RED, LI 00130+KE HOT BLOOD.') GO TO You can say GO TO: 10 PRINT 20 20 FORMAT (1X,'CAT') PRINT 30 30 FORMAT (1X,'DOG') GO TO 10 END The top line says to print what's in line 20, so the computer will print: CAT The next line says to print what's in line 30, so the computer will print: DOG The next line makes the computer go back to line 10. The computer will print CAT again, then DOG again, then jump back to line 10 again. . . . The computer will try to print the words CAT and DOG again and again, forever. STOP The computer understands the word STOP: PRINT 10 10 FORMAT (1X,'BUBBLE GUM') PRINT 20 20 FORMAT (1X,'SHAKESPEARE') STOP PRINT 30 30 FORMAT (1X,'DADA') END The top line says to print what's in line 10, so the computer will print BUBBLE GUM. The next line says to print what's in line 20, so the computer will print SHAKESPEARE. The next line says STOP, so the computer will stop. It will never print DADA. MATH FORTRAN handles math rather well. Integers versus real numbers FORTRAN distinguishes between integers and real numbers. Here's how FORTRAN defines them. . . . An integer contains no decimal point and no exponent. IntegerNot an integerComment -27 -27.0 An integer contains no decimal point. 50000 5E4 An integer contains no exponents. A real number contains either a decimal point or the letter E. Real numberNot a real number -27.0 -27 2.35E8 235000000 5E4 50000 The largest permissible integer is different from the largest permissible real: Computer Largest integerLargest realTiniest real PDP-11 using FORTRAN IV 327671.7E382.9E-39 PDP-11 using FORTRAN IV-PLUS 21474836471.7E382.9E-39 PDP-10 or Honeywell 343597383671.7E382.9E-39 IBM mainframe 21474836477.2E75 5.4E-79 CDC 2814749767106552.5E3223.1E-294 Integers are also called fixed-point numbers. Real numbers are called floating-point numbers. Variables In BASIC, X can stand for a number, such as 3.7. The same is true in FORTRAN. A variable can be a letter (such as X) or a letter-followed-by-a-combination-of-letters-and-digits (such as FUN4U2). The variable must be short: no more than 6 characters. AVERAGE is too long: say AVERAG instead. If the variable begins with I, J, K, L, M, or N, it stands for an integer. If it begins with some other letter, it stands for a real number. Using integer variables Here's a simple example: JUNKY=-47 PRINT 10, JUNKY 10 FORMAT (1X,I3) END Since JUNKY begins with J, it stands for an integer. The first line says JUNKY stands for the integer -47. The second line says to print JUNKY, using line 10. Line 10 explains how to print JUNKY. The I3 means: print it as an Integer having 3 characters. The computer will print: -47 If you change the I3 to I4, the computer will print JUNKY as an Integer having 4 characters. To print a total of 4 characters, the computer will print a blank space in front of -47, like this: -47 If you change to I5, the computer will print JUNKY as an Integer having 5 characters, by printing two blank spaces in front of -47: -47 If you change to I2, the computer will try to print JUNKY as an integer having 2 characters. But it's impossible to express -47 by using only 2 characters. The computer will obey the format and print 2 characters, but will make them asterisks: ** Another example: NUM=31.9 PRINT 10, NUM 10 FORMAT (1X,I4) END Since NUM begins with N, it stands for an integer. The program's top line tries to make NUM stand for 31.9; but that's impossible, since 31.9 isn't an integer. The computer will omit the .9 and make NUM stand for the integer 31. The computer will print 31, using an I4 format: 31 Example: JOE=-5.8 PRINT 10, JOE 10 FORMAT (1X,I4) END The computer will set JOE equal to the integer -5 and print it: -5 Example: JAIL=74 KRIMNL=829 PRINT 10, JAIL,KRIMNL 10 FORMAT (1X,I2,I3) END Since JAIL begins with J, and KRIMNL begins with K, they're both integers. The computer will print JAIL and KRIMNL, using the format in line 10. The format says to print a 2-character integer, then a 3-character integer. The computer will print: 74829 If you change the format to (1X,I2,4X,I3), the computer will print a 2-character integer, then 4 blanks, then a 3-character integer: 74 829 If you change the format to ___ 10 FORMAT (1X,'JAIL NUMBER',1X,I2,1X,'CONTAINS CRIMINAL',1X,I3) the computer will print JAIL NUMBER, then a blank, then a 2-character integer, then a blank, then CONTAINS CRIMINAL, then a blank, then a 3-character integer: JAIL NUMBER 74 CONTAINS CRIMINAL 829 Example: J=43 K=75 L=96 M=81 N=24 PRINT 10, J,K,L,M,N 10 FORMAT (1X,I2,I2,I2,I2,I2) END The computer will print 43, then 75, then 96, then 81, then 24: 4375968124 You can write that format more briefly: 10 FORMAT (1X,5I2) If you change the format to (1X,5I3), the computer will print each integer as 3 characters ___ a blank followed by two digits: 43 75 96 81 24 If you change the format to (1X,I3), the computer will print only one integer per line: 43 75 96 81 24 If you change the format to (1X,2I3), the computer will print 2 integers per line: 43 75 96 81 24 If you change the format to (1X,'GOSH',I3,1X,'SUPERB',I3,1X,'JEEP ERS'), the computer will print 2 integers per line: GOSH 43 SUPERB 75 JEEPERS GOSH 96 SUPERB 81 JEEPERS GOSH 24 SUPERB To be safe, use I14 format for integers. On most computers, I14 handles even the largest integers, and prints blank spaces between them. Using real variables The I format is only for integers. For real numbers, use F or G format instead. F format The F format is easy to understand: RADIUS=-586.39 PRINT 10, RADIUS 10 FORMAT (1X,F7.2) END Since RADIUS doesn't begin with I, J, K, L, M, or N, it stands for a real number. The first line says RADIUS stands for the real number -586.39. The second line says to print RADIUS, using the format in line 10. The F7.2 means: print it as a floating-point number having 7 characters, 2 of them after the decimal point. The computer will print: -586.39 If you change the F7.2 to a different format, the following chart shows what happens; in the chart, each þ represents a blank space: FormatWhat the computer printsComment F8.2 þ-586.39 To print 8 characters instead of 7, it prints a blank space at the beginning. F8.3 -586.390 To print 3 characters after the decimal point instead of 2, it prints a zero at the end. F8.1 þþ-586.4 To print 1 character after the decimal point instead of 2, it rounds the .39 to 4. F8.4 ******** To print 4 characters after the decimal point, the computer would have to print -586.3900. Since that requires more than 8 characters, the computer complains by printing asterisks. G format To print a real number, the safest format is G14.6, because G14.6 can handle any real number well, even if the number is very large or very tiny. G14.6 prints 14 characters altogether, 6 of which are significant digits. Here are examples of numbers printed in G14.6 format: þ-0.283941E-29 þþ0.293027þþþþ þþþ5.34523þþþþ þþþ39.4539þþþþ þþþ47802.3þþþþ þþþ986327.þþþþ þþ0.288341E+24 Example: PRUNES=17 PRINT 10, PRUNES 10 FORMAT (1X,G14.6) END Since PRUNES doesn't begin with I, J, K, L, M, or N, it stands for a real number. When the computer encounters the first line of the program, it will set PRUNES equal to the real number 17.0. It will print: 17.0000 The program will run faster if you change the top line to this: PRUNES=17.0 E format For real numbers, the usual formats are F and G, but another option is E. If you say E14.6 instead of G14.6, the computer will print an E in the answer. Here are examples: Using G14.6 formatUsing E14.6 format þ-0.283941E-29þ-0.283941E-29 þþ0.293027þþþþþþ0.293027E+00 þþþ5.34523þþþþþþ0.534523E+01 þþþ39.4539þþþþþþ0.394539E+02 þþþ47802.3þþþþþþ0.478023E+05 þþþ986327.þþþþþþ0.986327E+06 þþ0.288341E+24þþ0.288341E+24 The G14.6 format is easier for a human to read than E14.6. But most programmers are stupid, don't know about G14.6, and use E14.6 instead. P format FORTRAN's notation differs from BASIC. If you ask the computer to print 288341000000000000000000.0 in FORTRAN by using G14.6 (or E14.6), the computer will normally print a 0 before the decimal point, like this: 0.288341E+24. In BASIC, the computer will print a non-zero digit before the decimal point, like this: 2.88341E+23. If you're writing a program in FORTRAN, but you prefer BASIC's notation, ask for 1PG14.6 (or 1PE14.6). The 1P makes the computer imitate BASIC. But if a FORMAT contains 1PG, it must not contain F afterwards; this will print a wrong answer: FORMAT (1X,1PG14.6,F8.2)   Here is P. The F afterwards prints a wrong answer! Operations For addition, subtraction, multiplication, and division, FORTRAN uses the same symbols as BASIC. N=2*(3+1) S=7.3+2.1 PRINT 10, N,S 10 FORMAT (1X,I14,G14.6) END Since N is 8, and S is 9.4, the computer will print: 8 9.40000 Exponents For exponents, FORTRAN uses a double star: J=7**2 P=.5**3 PRINT 10, J,P 10 FORMAT (1X,I14,G14.6) END Since J is 72 (which is 49), and P is .53 (which is .125), the computer will print: 49 0.125000 For negative exponents, you need parentheses. You must say 6.1**(-2), not 6.1**-2. What type of answer? When you combine integers, the answer's an integer: 2+3 is 5 8-8 is 0 2*4 is 8 399/100 is 3 (not 3.99) 11/4 is 2 (not 2.75) 3/4 is 0 (not 0.75) 10**(-2) is 0 (not 0.01) When you combine real numbers, the answer is real: 4.1+2.9 is 7.0 (not 7) 8.0-8.0 is 0.0 (not 0) 399.0/100.0 is 3.99 11.0/4.0 is 2.75 3.0/4.0 is .75 10.0**(-2.0) is .01 When you combine an integer with a real number, the answer is real: 3+2.0 is 5.0 399/100.0 is 3.99 11/4.0 is 2.75 3/4.0 is .75 10.0**(-2) is .01 Compare these: 7/10*10 is 0(because 7/10 is 0) 7/10*10.0 is 0.0(because 0*10.0 is 0.0) 7/10.0*10 is 7.0(because 7/10.0 is .7) Example: JERK=20.0+30.9 PRINT 10, JERK 10 FORMAT (1X,I14) END Since JERK begins with J, it stands for an integer. Since 20.9+30.9 is 51.8, JERK stands for the integer 51. The computer will print: 51 Another example: APPLE=37/10 PRINT 10, APPLE 10 FORMAT (1X,G14.6) END Since APPLE begins with A, it stands for a real number. Since 37/10 is 3, APPLE stands for the real number 3.0. The computer will print: 3.00000 Crimes that slow down the computer cop If you commit one of these crimes, the computer will work slowly. . . . little crime: use a real number medium crime: mix reals with integers big crime: use a real exponent For example, the computer handles 2.0+2.0 slower than 2+2, because 2.0+2.0 is a little crime. The bigger the crime, the slower the computer works. For example, the computer handles 2.1+7 (which is a medium crime) slower than 2.1+7.0 (which is just a little crime). Likewise, X=0 (a medium crime) gets handled slower than X=0.0 (a little crime). 5.1**2.0 is a big crime, since its exponent (2.0) is real. The computer handles it slower than 5.1**2, which is just a medium crime. 5**3.1 is a gigantic crime, since it's a medium crime and a big crime simultaneously. Because the crime's so gigantic, some computers refuse to handle it. Say 5.0**3.1 instead. Advice about variables FORTRAN, like BASIC, distinguishes variables, constants, and expressions: X is a variable 2.7 is not a variable; it's a numeric constant `LOVE' is not a variable; it's a string constant X+Y is not a variable; it's an expression In a PRINT statement, some computers allow only variables. . . . allowed: PRINT 10, X not allowed: PRINT 10, 2.7instead, say X=2.7 and PRINT 10, X not allowed: PRINT 10, `LOVE'instead, say PRINT 10 and 10 FORMAT (1X,`LOVE') not allowed: PRINT 10, X+Yinstead, say Z=X+Y and PRINT 10, Z Other computers are more generous and allow anything. Find out about yours. To help other humans understand your program, use long variable names throughout your program. Say RADIUS, not R; say AREA, not A; say VOLUME, not V; say SUM, not S; say TOTAL, not T. Because FORTRAN's variables are restricted to six characters, you might have to omit the last few syllables (revolutions becomes REVOLU) or the last few vowels (RVLTNS). If you want a variable to be real, but its English name begins with I, J, K, L, M, or N, begin its FORTRAN name with an A (mass becomes AMAS; length becomes ALENGT or ALNGTH). If you want a variable to be an integer, but its English name doesn't begin with I, J, K, L, M, or N, begin its FORTRAN name with an I (population becomes IPOPUL) or misspell it (count becomes KOUNT) or choose a synonym (instead of position, say location, which is LOCATN). PLEASANT I/O You learned how to make the computer PRINT by using a FORMAT. Now you'll learn about PRINT's opposite (READ) and how to omit FORMATs altogether. READ The computer can READ. PRINT 10 10 FORMAT (1X,'TYPE SOME DIGITS') READ 20, N 20 FORMAT (I4) PRINT 30, N 30 FORMAT (1X,I4) END When you run the program, here's what happens. . . . The top two lines make the computer print: TYPE SOME DIGITS The word READ makes the computer wait for you to type something; it's like the BASIC word INPUT. The computer will wait for you to type the value of N, but line 20's FORMAT makes the computer read just the first 4 characters. For example, if you type ___ -75198622 the computer will read just the first 4 characters, which are -751; it will ignore the 98622; so N will be -751. Line 30's FORMAT makes the computer print: -751 Altogether, the run looks like this: The computer says:TYPE SOME DIGITS You say: -75198622 The computer replies:-751 Hassles Line 30's FORMAT contains a carriage control 1X, but line 20's FORMAT omits the carriage control. Put a carriage control in formats that PRINT, but not in formats that READ. On PDP computers, say ACCEPT instead of READ. Blank spaces If you input a blank space, the computer treats it as a zero. For example, suppose you input: -3 28219 Because of the I4 format, the computer will read just the first 4 characters, which are -3 2; the blank space between the 3 and the 2 is treated as a zero, so N will be -302. Suppose you input: 57 Because of the I4 format, the computer will read the 5, the 7, and two blanks. Since the blanks are treated as zeros, N will be 5700. Suppose you input: þþþ9527 Because of the I4 format, the computer will read the three beginning blanks and the 9. Since the blanks are treated as zeros, N will be 0009, which is 9. Line 30 makes the computer print: 9 Multiple variablesSuppose you write a program containing these lines: READ 20, L,M,N 20 FORMAT (I3,I4,2X,I2) When you run that program, suppose you input: 58194138972824 The I3 format makes the first 3 characters (581) be L. The I4 format makes the next 4 characters (9413) be M. The 2X format makes the next 2 characters (89) be skipped over. The I2 format makes the next two characters (72) be N. The remaining characters (824) are ignored. So the line is split like this. . . . Line you input: 58194138972824 Fields in the FORMAT statement: I4 2XI2 Variables in the READ statement: L ³ ³ ³ ³ ³ ³I3³ ³ ³ ³ ³ ³ M ³ ³N³ Suppose you write a program containing these lines: READ 20, J,K,L,M,N 20 FORMAT (2I3) The format says to read two 3-character integers on each line. Suppose you input: 78345692 85431684 46185327 J will be 783, and K will be 456. L will be 854, and M will be 316. N will be 461. Real variables Here's how to input a real number: PRINT 10 10 FORMAT (1X,'TYPE SOME DIGITS') READ 20, P 20 FORMAT (F6.2) PRINT 30, P 30 FORMAT (1X,G14.6) END The F6.2 format means: read 6 characters; if they don't contain the decimal point, insert it before the last 2 digits. For example, suppose you input: 327514968 The computer reads the first 6 characters (327514). Since they don't contain the decimal point, the computer inserts it before the last 2 digits, so P is 3275.14. Line 30 prints: 3275.14 Suppose you input: 7.5423967 The computer reads the first 6 characters (7.5423). Since they already contain the decimal point, P is 7.5423. Line 30 says to print that number by using 6 significant digits, so the computer prints: 7.54230 Suppose you input: 497E3 The computer reads 6 characters (497E3, followed by a blank). Since blanks are treated as zeros, the computer gets 497E30. Since 497E30 doesn't contain the decimal point, the computer inserts it before the last 2 digits, so P is 4.97E30. Line 30 prints: 0.497000E+31 Omitting formats Most computers let you omit numeric formats. This program works on most modern computers (such as computers having FORTRAN 77, PDP-20 computers, PDP-10 computers using FORTRAN 10, PDP-11 computers using FORTRAN IV-PLUS, CDC computers using FORTRAN IV-EXTENDED, and IBM computers using FORTRAN H-EXTENDED): PRINT 10 On PDP computers, 10 FORMAT (1X,'TYPE TWO INTEGERS')say TYPE instead of READ *, M,N PRINT, and ACCEPT ISUM=M+N instead of READ. PRINT *, ISUM END The word READ is followed by an asterisk, instead of a FORMAT number. The last PRINT is followed by an asterisk also. The asterisk makes the computer invent its own FORMAT. To make the program add 241 and 82976, input the numbers, separated by a comma: 241,82976 The computer will notice the comma's location and automatically use an I3 format for 241, a 1X format to skip over the comma, and an I5 format for 82976. To print ISUM, the computer will use a safe format, such as I14 or I15. By omitting formats, you gain two advantages: 1. You can write FORTRAN programs more quickly. 2. The person who inputs doesn't have to worry about whether his spacing matches the format. The computer invents a format that matches his input. Different versions On CDC computers using TS FORTRAN and on Honeywell computers, omit the asterisk after READ and PRINT: PRINT 10 10 FORMAT (1X,'TYPE THE NUMBERS') READ, M,N ISUM=M+N PRINT, ISUM END On PDP-10 computers using F40 FORTRAN, and on PDP-11 computers using regular FORTRAN IV, you need FORMATs, but omit the number in the I format: TYPE 10 10 FORMAT (1X,'TYPE THE NUMBERS') ACCEPT 20, M,N 20 FORMAT (1X,2I) ISUM=M+N TYPE 30, ISUM 30 FORMAT (1X,I) END Real numbers You can use similar short cuts for real numbers. LOGIC You learned how to say GO TO and STOP. Taking those concepts further, let's see how to say IF and DO and give a computed GO TO. IF FORTRAN uses these clauses: Clause Meaning IF (I .LT. 5)If I is Less Than 5 IF (I .GT. 5)If I is Greater Than 5 IF (I .LE. 5)If I is Less than or Equal to 5 IF (I .GE. 5)If I is Greater than or Equal to 5 IF (I .EQ. 5)If I is EQual to 5 IF (I .NE. 5)If I is Not Equal to 5 Notice that each relational operator (such as LT) must be enclosed in periods, and each condition (such as I .LT. 5) must be enclosed in parentheses. By using those clauses, you can build statements: Statement Meaning IF (I .LT. 5) J=3If I is Less Than 5, let J=3 IF (I .LT. 5) GO TO 80If I is Less Than 5, go to line 80. IF (I .LT. 5) STOPIf I is Less Than 5, stop. IF (I .LT. 5) PRINT 10, JIf I is Less Than 5, print J using line 10's FORMAT. You can use the words AND and OR: Idea How to say it in FORTRAN If I is 2 or 9 or 13IF (I .EQ. 2 .OR. I .EQ. 9 .OR. I .EQ. 13) If I is an integer from 1 to 8IF (I .GE. 1 .AND. I .LE. 8) If X